/*
 * Copyright ©2018 贾维程. All rights reserved.
 */

package com.rtmart.imageupload.controller.image;

import com.rtmart.imageupload.Tools.DateTools;
import com.rtmart.imageupload.Tools.FileTools;
import com.rtmart.imageupload.entity.Item;
import com.rtmart.imageupload.repository.ItemRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.File;

@Controller
@RequestMapping(value = "/image/")
@PreAuthorize("hasAnyRole('ROLE_root','ROLE_admin')")
public class ImageController {
/*
    @Value("${img.location}")
    private String basePath;

    @Autowired
    private ItemRepository itemRepository;

    @GetMapping("delete/{id}/{url}")
    public String deleteImage(@PathVariable Long id, @PathVariable String url){
        Item item = itemRepository.getOne(id);
        File file = new File(basePath + "/" + item.getNo() + "/" + url);
        FileTools.deleteDir(file);
        return "redirect:/item/edit/" + item.getId();
    }

    @GetMapping("delete/{id}")
    public String deleteAllImage(@PathVariable Long id) {
        Item item = itemRepository.getOne(id);
        File file = new File(basePath + "/" + item.getNo() + "/");
        FileTools.deleteDir(file);
        return "redirect:/item/edit/" + item.getId();
    }*/
}
